<?php

namespace App\Models\Cart;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Model;

/**
 * 购物车模型类
 *
 * @author WangBin
 * @date 2021-09-24
 * @package App\Models\Goods
 */
class Carts extends BaseModel
{
    protected $table = 'b2c_carts';
    protected $primaryKey = 'cart_id';

    /**
     * 根据购物车ID获取
     *
     * @param int $cartId
     * @return \Illuminate\Database\Eloquent\Builder|Model|object|null
     */
    public static function getById(int $cartId)
    {
        return Carts::query()->where('cart_id', $cartId)->first();
    }

    /**
     * 获取客户购物车
     *
     * @param int $customerId
     * @param bool $fastBuy
     * @return \Illuminate\Database\Eloquent\Builder|Model|object|null
     */
    public static function getByCustomerId(int $customerId, int $fastBuy = 0)
    {
        return Carts::query()->where('customer_id', $customerId)->where('fast_buy', $fastBuy)->first();
    }
}
